// filePath：renwu.ts #startLine: 1 #endLine: 60
import request from "@/utils/request";

// 请求参数类型
export type taskParamsType = {
    gradeLevel?: number | null;
    pageIndex: number;
    pageSize: number;
}

// 响应数据类型
type taskResponseType = {
    total: number;
    list: taskType[];
}

// 任务数据类型
export type taskType = {
    id: number;
    title: string;
    gradeLevel: number;
    createUserName: string;
    createTime: string;
    deleted: boolean;
}

// 任务详情响应类型
export type TaskDetail = {
    id: number;
    gradeLevel: number;
    title: string;
    paperItems: PaperItem[];
}

export type PaperItem = {
    id: number;
    name: string;
    questionCount: number;
    score: number;
    createTime: string;
    createUser: number;
    subjectId: number;
    paperType: number;
    frameTextContentId: number;
    allClasses: any;
    subjectName: string; // 添加 subjectName 属性
}

// 任务分页接口
export function taskPage(data: taskParamsType) {
    return request.post<taskResponseType>('/api/admin/task/page', data)
}

// 任务详情接口
export function taskSelect(id: number) {
    return request.post<TaskDetail>(`/api/admin/task/select/${id}`)
}

// 任务删除接口
export function taskDelete(id: number) {
    return request.post<{code: number; message: string; response: null}>(`/api/admin/task/delete/${id}`)
}


export function subjectList() {
    return request.post<Subject[]>('/api/admin/education/subject/list');
}

// 添加学科类型定义
export type Subject = {
    id: number;
    name: string;
    level: number;
    levelName: string;
    itemOrder: number | null;
    deleted: boolean;
};

export type PaperPageParams = {
    gradeLevel?: number | null;
    subjectId?: number | null;
    pageIndex: number;
    pageSize: number;
  }
  
  // 试卷分页响应类型
  export type PaperPageResponse = {
    total: number;
    list: PaperItem[];
  }
  
  // 试卷分页接口
  export function paperPage(data: PaperPageParams) {
    return request.post<PaperPageResponse>('/api/admin/exam/paper/page', data);
  }


// 添加任务编辑接口
export function taskEdit(data: TaskEditParams) {
    return request.post<TaskDetail>('/api/admin/task/edit', data)
  }
  
  // 定义任务编辑请求参数类型
  export type TaskEditParams = {
    id?: number; // 任务ID（编辑时必需，新增时可选）
    gradeLevel: number;
    title: string;
    paperItems: PaperItemForEdit[];
  }
  
  // 为编辑接口定义精简的试卷项类型（去除前端添加的额外属性）
  export type PaperItemForEdit = {
    id: number;
    name: string;
    questionCount: number;
    score: number;
    createTime: string;
    createUser: number;
    subjectId: number;
    paperType: number;
    frameTextContentId: number;
  }
  